/**
 * 生成视频切片命令
 */

const path = require("path");
const ffmpegPath = path.join(__dirname , '../', 'ffmpeg', 'ffmpeg.exe');


function slice_video(filepath, savePath, duration, indexFile, keyFileName) {


    // 不加密
    let cmdStr = `"${ffmpegPath}" -i ${filepath} -c copy -map 0 -f segment -segment_list "${indexFile}" -segment_time ${duration} "${savePath}"`;

    if (/^.+\.keyinfo$/.test(keyFileName)) {
        // 需要加密
        cmdStr = `"${ffmpegPath}" -y -i ${filepath} -hls_time ${duration} -hls_key_info_file ${keyFileName} -hls_playlist_type vod -hls_segment_filename "${savePath}" "${indexFile}"`;
    }



    return cmdStr;
}

module.exports = slice_video;